package io.tij;

import java.nio.CharBuffer;

public class UsingBuffers {
	
	public static void symmetricScramble(CharBuffer cb){
		while(cb.hasRemaining()){
			cb.mark();
			char c1 = cb.get();
			char c2 = cb.get();
			cb.reset();
			cb.put(c2);
			cb.put(c1);
		}
	}
	
	public static void main(String[] args){
		char[] data = "UsingBuffers".toCharArray();
		CharBuffer cb = CharBuffer.allocate(data.length);
		cb.put(data);
		System.out.println(cb.rewind());
		symmetricScramble(cb);
		System.out.println(cb.rewind());
		symmetricScramble(cb);
		System.out.println(cb.rewind());		
	}

}
